cmake_minimum_required(VERSION 3.10)
project(rosbag_recorder)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
  mavros_msgs
  rosbag
)

find_package(YAML-CPP REQUIRED)

catkin_package()

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
  ${YAML_CPP_INCLUDE_DIRS}
)

add_executable(${PROJECT_NAME}_node src/rosbag_recorder_node.cpp)

target_link_libraries(${PROJECT_NAME}_node
  ${catkin_LIBRARIES}
  yaml-cpp
)

# 创建 build 和 dist 路径
set(OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/rosrecord)
set(CONFIG_DIRECTORY ${OUTPUT_DIRECTORY}/config)
set(BIN_DIRECTORY ${OUTPUT_DIRECTORY}/bin)

# 确保安装目录存在
file(MAKE_DIRECTORY ${BIN_DIRECTORY})
file(MAKE_DIRECTORY ${CONFIG_DIRECTORY})

message(STATUS "******************${OUTPUT_DIRECTORY}")

# 安装目标到 dist 目录
install(TARGETS ${PROJECT_NAME}_node
  RUNTIME DESTINATION ${BIN_DIRECTORY}
)

# 安装配置文件到 dist 目录
install(FILES config/config.yaml
  DESTINATION ${CONFIG_DIRECTORY}
)

# 安装配置文件到 dist 目录
install(FILES start.sh stop.sh
  DESTINATION ${OUTPUT_DIRECTORY}
)
